package com.wicket.okrframework.web.contorller;

import com.github.pagehelper.Page;
import com.wicket.okrframework.biz.service.PowerService;
import com.wicket.okrframework.biz.service.dto.req.*;
import com.wicket.okrframework.biz.service.dto.res.*;
import com.wicket.okrframework.common.ro.OkrResult;
import com.wicket.okrframework.common.util.CommonFunctionHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@RestController
@RequestMapping("/base/power/")
public class PowerController {

    @Autowired
    PowerService powerService;

    /**
     * D1-2查询管理的部门列表
     */
    @PostMapping("queryManageDeptList")
    public OkrResult<QueryManageDeptListRespDto> queryManageDeptList(@RequestBody @Validated QueryManageDeptListReqDto reqDTO) {
        Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(), reqDTO.getPageSize());

        QueryManageDeptListRespDto retData = powerService.queryManageDeptList(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);

    }

    /**
   * D1-2新增管理的部门
   */
    @PostMapping("addManageDept")
    public OkrResult<AddManageDeptRespDto> addManageDept(@RequestBody @Validated AddManageDeptReqDto reqDTO){
    return OkrResult.success(powerService.addManageDept(reqDTO));
    }

    /**
   * D1-2查询权限分配的角色列表
   */
    @PostMapping("queryTributPowerRoleList")
    public OkrResult<QueryTributPowerRoleListRespDto> queryTributPowerRoleList(@RequestBody @Validated QueryTributPowerRoleListReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryTributPowerRoleListRespDto retData = powerService.queryTributPowerRoleList(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D1-2查询权限列表
   */
    @PostMapping("queryPowerList")
    public OkrResult<QueryPowerListRespDto> queryPowerList(@RequestBody @Validated QueryPowerListReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryPowerListRespDto retData = powerService.queryPowerList(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D1-获取用户全部权限
   */
    @PostMapping("getUserAllPower")
    public OkrResult<GetUserAllPowerRespDto> getUserAllPower(@RequestBody @Validated GetUserAllPowerReqDto reqDTO){
    return OkrResult.success(powerService.getUserAllPower(reqDTO));
    }

    /**
   * D1-2查管理的部门列表(边界)
   */
    @PostMapping("queryManageDeptListBorder")
    public OkrResult<QueryManageDeptListBorderRespDto> queryManageDeptListBorder(@RequestBody @Validated QueryManageDeptListBorderReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryManageDeptListBorderRespDto retData = powerService.queryManageDeptListBorder(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D1-存档权限分配缓存
   */
    @PostMapping("archiveTributPowerRedis")
    public OkrResult<ArchiveTributPowerRedisRespDto> archiveTributPowerRedis(@RequestBody @Validated ArchiveTributPowerRedisReqDto reqDTO){
    return OkrResult.success(powerService.archiveTributPowerRedis(reqDTO));
    }

    /**
   * 存档权限分配
   */
    @PostMapping("archiveTributPower")
    public OkrResult<ArchiveTributPowerRespDto> archiveTributPower(@RequestBody @Validated ArchiveTributPowerReqDto reqDTO){
    return OkrResult.success(powerService.archiveTributPower(reqDTO));
    }

    /**
   * D1-2查询权限分配详情
   */
    @PostMapping("queryTributPowerDetail")
    public OkrResult<QueryTributPowerDetailRespDto> queryTributPowerDetail(@RequestBody @Validated QueryTributPowerDetailReqDto reqDTO){
    return OkrResult.success(powerService.queryTributPowerDetail(reqDTO));
    }

    /**
   * D1-2查询权限分配列表
   */
    @PostMapping("queryTributPowerList")
    public OkrResult<QueryTributPowerListRespDto> queryTributPowerList(@RequestBody @Validated QueryTributPowerListReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryTributPowerListRespDto retData = powerService.queryTributPowerList(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D1-2修改权限（平台）
   */
    @PostMapping("updatePower")
    public OkrResult<UpdatePowerRespDto> updatePower(@RequestBody @Validated UpdatePowerReqDto reqDTO){
    return OkrResult.success(powerService.updatePower(reqDTO));
    }

    /**
     * D1-2查询部门管理权限详情(边界)
     */
    @PostMapping("queryDeptPowerDetailBorder")
    public OkrResult<QueryDeptPowerDetailBorderRespDto> queryDeptPowerDetailBorder(@RequestBody @Validated QueryDeptPowerDetailBorderReqDto reqDTO) {
        return OkrResult.success(powerService.queryDeptPowerDetailBorder(reqDTO));
    }

    /**
   * D1-2存档部门权限分配
   */
    @PostMapping("archiveTribuDeptPower")
    public OkrResult<ArchiveTribuDeptPowerRespDto> archiveTribuDeptPower(@RequestBody @Validated ArchiveTribuDeptPowerReqDto reqDTO){
    return OkrResult.success(powerService.archiveTribuDeptPower(reqDTO));
    }

    /**
   * D1-2查询分配的部门权限列表
   */
    @PostMapping("queryTribuDeptPowerList")
    public OkrResult<QueryTribuDeptPowerListRespDto> queryTribuDeptPowerList(@RequestBody @Validated QueryTribuDeptPowerListReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryTribuDeptPowerListRespDto retData = powerService.queryTribuDeptPowerList(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D1-2查询权限分配的部门职务列表
   */
    @PostMapping("queryTributPowerDeptPositionList")
    public OkrResult<QueryTributPowerDeptPositionListRespDto> queryTributPowerDeptPositionList(@RequestBody @Validated QueryTributPowerDeptPositionListReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryTributPowerDeptPositionListRespDto retData = powerService.queryTributPowerDeptPositionList(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D1-2查询权限分配的职务列表
   */
    @PostMapping("queryTributPowerPositionList")
    public OkrResult<QueryTributPowerPositionListRespDto> queryTributPowerPositionList(@RequestBody @Validated QueryTributPowerPositionListReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryTributPowerPositionListRespDto retData = powerService.queryTributPowerPositionList(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D1-2查询权限分配的员工列表
   */
    @PostMapping("queryTributPowerMemberList")
    public OkrResult<QueryTributPowerMemberListRespDto> queryTributPowerMemberList(@RequestBody @Validated QueryTributPowerMemberListReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryTributPowerMemberListRespDto retData = powerService.queryTributPowerMemberList(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D1-2查询权限分配的部门列表
   */
    @PostMapping("queryTributPowerDeptList")
    public OkrResult<QueryTributPowerDeptListRespDto> queryTributPowerDeptList(@RequestBody @Validated QueryTributPowerDeptListReqDto reqDTO){
        // TODO: 2023/6/15 特殊分页的controller层要注释掉 
        // Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryTributPowerDeptListRespDto retData = powerService.queryTributPowerDeptList(reqDTO);

//        retData.setPageNum(page.getPageNum());
//        retData.setPageSize(page.getPageSize());
//        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D1-2存档权限
   */
    @PostMapping("archivePower")
    public OkrResult<ArchivePowerRespDto> archivePower(@RequestBody @Validated ArchivePowerReqDto reqDTO){
    return OkrResult.success(powerService.archivePower(reqDTO));
    }

    /**
   * D1-2新增权限分配
   */
    @PostMapping("addTributPower")
    public OkrResult<AddTributPowerRespDto> addTributPower(@RequestBody @Validated AddTributPowerReqDto reqDTO){
    return OkrResult.success(powerService.addTributPower(reqDTO));
    }

    /**
   * D1-2删除权限
   */
    @PostMapping("deletePower")
    public OkrResult<DeletePowerRespDto> deletePower(@RequestBody @Validated DeletePowerReqDto reqDTO){
    return OkrResult.success(powerService.deletePower(reqDTO));
    }

    /**
   * D1-2新增权限(平台)
   */
    @PostMapping("addPower")
    public OkrResult<AddPowerRespDto> addPower(@RequestBody @Validated AddPowerReqDto reqDTO){
    return OkrResult.success(powerService.addPower(reqDTO));
    }

    /**
   * D1-2查询权限详情
   */
    @PostMapping("queryPowerDetail")
    public OkrResult<QueryPowerDetailRespDto> queryPowerDetail(@RequestBody @Validated QueryPowerDetailReqDto reqDTO){
    return OkrResult.success(powerService.queryPowerDetail(reqDTO));
    }

    /**
   * D1-2查询权限分配的成员列表
   */
    @PostMapping("queryTributPowerInductionRecordList")
    public OkrResult<QueryTributPowerInductionRecordListRespDto> queryTributPowerInductionRecordList(@RequestBody @Validated QueryTributPowerInductionRecordListReqDto reqDTO){
    //Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryTributPowerInductionRecordListRespDto retData = powerService.queryTributPowerInductionRecordList(reqDTO);

//        retData.setPageNum(page.getPageNum());
//        retData.setPageSize(page.getPageSize());
//        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D1-2批量查询权限分配(公共)（跨服务）
   */
    @PostMapping("batchQueryTributPowerCom")
    public OkrResult<BatchQueryTributPowerComRespDto> batchQueryTributPowerCom(@RequestBody @Validated BatchQueryTributPowerComReqDto reqDTO){
    return OkrResult.success(powerService.batchQueryTributPowerCom(reqDTO));
    }
/**
   * D1判断组织架构唯一权限(公共)
   */
    @PostMapping("judgeOrgOnlyPowerCom")
    public OkrResult<JudgeOrgOnlyPowerComRespDto> judgeOrgOnlyPowerCom(@RequestBody @Validated JudgeOrgOnlyPowerComReqDto reqDTO){
    return OkrResult.success(powerService.judgeOrgOnlyPowerCom(reqDTO));
    }
/**
   * D1查询当前个人本地权限(公共)
   */
    @PostMapping("queryCurrentPersonalLocalPowerDetailCom")
    public OkrResult<QueryCurrentPersonalLocalPowerDetailComRespDto> queryCurrentPersonalLocalPowerDetailCom(@RequestBody @Validated QueryCurrentPersonalLocalPowerDetailComReqDto reqDTO){
    return OkrResult.success(powerService.queryCurrentPersonalLocalPowerDetailCom(reqDTO));
    }
/**
   * D1-2执行权限更新状态(公共)
   */
    @PostMapping("implementPowerUpdateStatusCom")
    public OkrResult<ImplementPowerUpdateStatusComRespDto> implementPowerUpdateStatusCom(@RequestBody @Validated ImplementPowerUpdateStatusComReqDto reqDTO){
    return OkrResult.success(powerService.implementPowerUpdateStatusCom(reqDTO));
    }
/**
   * D1查询当前个人权限(公共)
   */
    @PostMapping("queryCurrentPersonalPowerDetailCom")
    public OkrResult<QueryCurrentPersonalPowerDetailComRespDto> queryCurrentPersonalPowerDetailCom(@RequestBody @Validated QueryCurrentPersonalPowerDetailComReqDto reqDTO){
    return OkrResult.success(powerService.queryCurrentPersonalPowerDetailCom(reqDTO));
    }
/**
   * D1查询当前用户指定角色权限(公共)
   */
    @PostMapping("queryCurrentUserRolePowerDetailCom")
    public OkrResult<QueryCurrentUserRolePowerDetailComRespDto> queryCurrentUserRolePowerDetailCom(@RequestBody @Validated QueryCurrentUserRolePowerDetailComReqDto reqDTO){
    return OkrResult.success(powerService.queryCurrentUserRolePowerDetailCom(reqDTO));
    }

    /**
   * D1-2查询当前就职记录部门管理权限详情(公共)
   */
    @PostMapping("queryPresentInaugurationDeptMgtPowerDetailCom")
    public OkrResult<QueryPresentInaugurationDeptMgtPowerDetailComRespDto> queryPresentInaugurationDeptMgtPowerDetailCom(@RequestBody @Validated QueryPresentInaugurationDeptMgtPowerDetailComReqDto reqDTO){
    return OkrResult.success(powerService.queryPresentInaugurationDeptMgtPowerDetailCom(reqDTO));
    }
    /**
   * D1-2查询当前员工角色权限列表(公共)
   */
    @PostMapping("queryCurrentStaffRolePowerListCom")
    public OkrResult<QueryCurrentStaffRolePowerListComRespDto> queryCurrentStaffRolePowerListCom(@RequestBody @Validated QueryCurrentStaffRolePowerListComReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryCurrentStaffRolePowerListComRespDto retData = powerService.queryCurrentStaffRolePowerListCom(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }
/**
   * D1-2查询当前用户就职记录权限列表(公共)
   */
    @PostMapping("queryCurrentUserRecordTributPowerListCom")
    public OkrResult<QueryCurrentUserRecordTributPowerListComRespDto> queryCurrentUserRecordTributPowerListCom(@RequestBody @Validated QueryCurrentUserRecordTributPowerListComReqDto reqDTO){
    return OkrResult.success(powerService.queryCurrentUserRecordTributPowerListCom(reqDTO));
    }
/**
   * D1-2查询当前用户就职记录权限(公共)
   */
    @PostMapping("queryCurrentUserRecordTributPowerDetailCom")
    public OkrResult<QueryCurrentUserRecordTributPowerDetailComRespDto> queryCurrentUserRecordTributPowerDetailCom(@RequestBody @Validated QueryCurrentUserRecordTributPowerDetailComReqDto reqDTO){
    return OkrResult.success(powerService.queryCurrentUserRecordTributPowerDetailCom(reqDTO));
    }
/**
   * D1-2批量查询当前用户就职记录权限(公共)
   */
    @PostMapping("batchQueryCurrentUserRecordTributPowerCom")
    public OkrResult<BatchQueryCurrentUserRecordTributPowerComRespDto> batchQueryCurrentUserRecordTributPowerCom(@RequestBody @Validated BatchQueryCurrentUserRecordTributPowerComReqDto reqDTO){
    return OkrResult.success(powerService.batchQueryCurrentUserRecordTributPowerCom(reqDTO));
    }
/**
   * D1-2-14删除管理的部门
   */
    @PostMapping("deleteManageDept")
    public OkrResult<DeleteManageDeptRespDto> deleteManageDept(@RequestBody @Validated DeleteManageDeptReqDto reqDTO){
    return OkrResult.success(powerService.deleteManageDept(reqDTO));
    }
/**
   * D1-2批量查询权限分配by分配对象(公共)
   */
    @PostMapping("batchQueryTributPowerComByObj")
    public OkrResult<BatchQueryTributPowerComByObjRespDto> batchQueryTributPowerComByObj(@RequestBody @Validated BatchQueryTributPowerComByObjReqDto reqDTO){
    return OkrResult.success(powerService.batchQueryTributPowerComByObj(reqDTO));
    }
/**
   * D1-2查询部门管理权限详情
   */
    @PostMapping("queryDeptPowerDetail")
    public OkrResult<QueryDeptPowerDetailRespDto> queryDeptPowerDetail(@RequestBody @Validated QueryDeptPowerDetailReqDto reqDTO){
    return OkrResult.success(powerService.queryDeptPowerDetail(reqDTO));
    }
/**
   * D1查询一级部门下分配权限人员列表(管理)
   */
    @PostMapping("queryOneDeptTributPowerStaffList")
    public OkrResult<QueryOneDeptTributPowerStaffListRespDto> queryOneDeptTributPowerStaffList(@RequestBody @Validated QueryOneDeptTributPowerStaffListReqDto reqDTO){
        Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryOneDeptTributPowerStaffListRespDto retData = powerService.queryOneDeptTributPowerStaffList(reqDTO);
        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    }
/**
   * D1-3查询当前员工角色权限列表
   */
    @PostMapping("queryCurrentStaffRolePowerList")
    public OkrResult<QueryCurrentStaffRolePowerListRespDto> queryCurrentStaffRolePowerList(@RequestBody @Validated QueryCurrentStaffRolePowerListReqDto reqDTO){
    return OkrResult.success(powerService.queryCurrentStaffRolePowerList(reqDTO));
    }
/**
   * D1查询当前用户权限列表(公共)
   */
    @PostMapping("queryCurrentUserPowerListCom")
    public OkrResult<QueryCurrentUserPowerListComRespDto> queryCurrentUserPowerListCom(@RequestBody @Validated QueryCurrentUserPowerListComReqDto reqDTO){
    return OkrResult.success(powerService.queryCurrentUserPowerListCom(reqDTO));
    }

}
